﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Conectorws;

namespace GenVisitas
{
    public partial class login : Form
    {
        public static Form1 frmVisitas = new Form1();
        public static int tipo=0;
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (autenticacion(txtUsuario.Text, txtClave.Text))
            {
               

                Form1.Usuario = txtUsuario.Text;
                this.Visible = false;
                if (tipo == 2)
                    Form1.isAdmin = true;
                frmVisitas.frmLogin = this;
                frmVisitas.Show();
            }
            else
                MessageBox.Show("Usuario o clave incorrectos", "Error");
        }

        private bool autenticacion(string usuario,string password) {
            tipo = ServicioCN.Autenticacion(usuario, password);
            if (tipo > 0)
            {
                
                return true;
            }
            return false;
        }

        private void txtClave_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r') {
                button1_Click(sender, e);
            }
        }
    }
}
